package com.application;

import android.view.View;
import android.widget.Toast;

import androidx.lifecycle.ViewModelProvider;

import com.alibaba.android.arouter.launcher.ARouter;
import com.application.base.BaseActivity;
import com.application.databinding.ActivityLoginBinding;
import com.application.util.ARouterConstants;
import com.application.viewmodel.LoginViewModel;

public class LoginActivity extends BaseActivity<ActivityLoginBinding, LoginViewModel> {


    @Override
    protected int initLayoutId() {
        return R.layout.activity_login;
    }

    @Override
    protected int initVariableId() {
        return BR.loginViewModel;
    }

    @Override
    protected LoginViewModel initViewModel() {
        return new ViewModelProvider(this).get(LoginViewModel.class);
    }

    @Override
    protected void initData() {
        binding.setLogin(this);
    }

    @Override
    protected void initViewObservable() {
        super.initViewObservable();
    }

    public void loginToMain(View view) {
        if (viewModel.validateLogin()) {
            String login_username = viewModel.username.getValue();
            ARouter.getInstance()
                    .build(ARouterConstants.ACTIVITY_URL_MAIN_FRAGMENT)
                    .withString("username", login_username)
                    .navigation();

            finish();
        } else {
            Toast.makeText(this, viewModel.errorMessage(), Toast.LENGTH_SHORT).show();
        }

    }

    public void toWebWeChat(View view) {
        ARouter.getInstance()
                .build(ARouterConstants.ACTIVITY_URL_WEB_WECHAT)
                .withString("url", "https://weixin.qq.com/")
                .navigation();
    }
}